//
//  VisitorView.swift
//  weibo
//
//  Created by hm on 2020/4/21.
//  Copyright © 2020 hm. All rights reserved.
//

import UIKit

class VisitorView: UIView {

    class func instance() -> VisitorView {
        //绑定xib
        return Bundle.main.loadNibNamed("VisitorView", owner: nil, options: nil)?.first as! VisitorView
    }

    // Mark:- 控件属性
    @IBOutlet weak var rotationView: UIImageView!
    @IBOutlet weak var iconView: UIImageView!
    @IBOutlet weak var tipView: UILabel!
    @IBOutlet weak var registerBtn: UIButton!
    @IBOutlet weak var loginBtn: UIButton!
    
    
    // Mark:- 自定义函数
    func setupVisitorViewInfo(iconName: String, title: String){
        iconView.image = UIImage(named: iconName)
        tipView.text = title
        rotationView.isHidden = true
    }
    
    //启动转盘动画
    func addRotationAnim(){
        //创建动画
        //沿着z轴旋转
        let rotationAnim = CABasicAnimation(keyPath: "transform.rotation.z")
        rotationAnim.fromValue = 0
        rotationAnim.toValue = Double.pi * 2
        rotationAnim.repeatCount = MAXFLOAT
        //避免应用退出后恢复，动画暂停
        rotationAnim.isRemovedOnCompletion = false
        //转一圈耗时1s
        rotationAnim.duration = 5
        
        //将动画添加layer中
        rotationView.layer.add(rotationAnim, forKey: nil)
    }
}
